#include "mylabel.h"
#include <QDebug>
#include <QEvent>
#include <QMouseEvent>
#include <QKeyEvent>

mylabel::mylabel(QWidget* parent): QLabel(parent)
{

}

//鼠标进入窗口时触发
void mylabel::enterEvent(QEvent *event)
{
    qDebug() << "鼠标进入";
}

void mylabel::leaveEvent(QEvent *event)
{
    qDebug() << "鼠标退出";
}

void mylabel::mousePressEvent(QMouseEvent *ev)
{
    qDebug() << ev->pos();
    if(ev->button() == Qt::LeftButton)
    {
        qDebug() << "左键点击";
    }
    if(ev->button() == Qt::RightButton)
    {
        qDebug() << "右键点击";
    }
}

void mylabel::keyPressEvent(QKeyEvent *ev)
{
    qDebug() << "jin";
    if(ev->key() == Qt::Key_W)
    {
        qDebug("w被按下");
    }
}

void mylabel::mouseReleaseEvent(QMouseEvent *ev)
{
    qDebug() << "鼠标被释放";
}
